PROGRAM_NAME='Melton Main - Panels'
(***********************************************************)
(***********************************************************)
(*  FILE_LAST_MODIFIED_ON: 04/05/2006  AT: 09:00:25        *)
(***********************************************************)
(* System Type : NetLinx                                   *)
(***********************************************************)
(* REV HISTORY:                                            *)
(***********************************************************)
(*
    $History: $
*)

(***********************************************************)
(*        SUBROUTINE/FUNCTION DEFINITIONS GO BELOW         *)
(***********************************************************)
(* EXAMPLE: DEFINE_FUNCTION <RETURN_TYPE> <NAME> (<PARAMETERS>) *)
(* EXAMPLE: DEFINE_CALL '<NAME>' (<PARAMETERS>) *)
Define_Call 'IPAD_PAGE_FLIPS' (Dev dvDevice, Integer nBtn, Integer nPanel)
{
    Stack_Var Integer nI
    Local_Var Char strSubSystemPage[30]
    
    Call 'DEBUG_OUTPUT' (__LINE__,"'Call IPAD_PAGE_FLIPS (',Itoa(dvDevice.Number),':',Itoa(dvDevice.Port),':',Itoa(dvDevice.System),', ',Itoa(nBtn),')'")
    Switch (sUI[nPanel].nZone)
    {
	Case cnFamilyID:
	Case cnMBedID:
	{
	    strSubSystemPage = 'SOURCE Select Subsystem 02'
	}
	Default: // basic audio zones
	{
	    strSubSystemPage = 'SOURCE Select Subsystem 01'
	}
    }
    Switch (nBtn)
    {
	Case 1: // Off
	{
	    On[dvDevice,cnOffConfirmation]
	    Send_Command dvDevice,"'PAGE-START Main Page'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	    Send_Command dvDevice,"'@PPN-WEATHER Popup'"
	}
	Case 2: // Local DTV
	{
	    Switch (sUI[nPanel].nZone)
	    {
		Case cnFamilyID:
		{
		    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daFamilyDtvPanels)
		    Pulse[vdvFamilyDtv,255] // rebuild events
		}
		//Case cnMBedID:
		//{
		//    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daMBedDtvPanels)
		//    Pulse[vdvMBedDtv,255] // rebuild events
		//}
	    }
	    Send_Command dvDevice,"'PAGE-VIDEO DirecTV DVR'"
	    Send_Command dvDevice,"'@PPN-VIDEO HDTV FAVORITES Page 1'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 3: // Local DVD
	{
	    Switch (sUI[nPanel].nZone)
	    {
		Case cnFamilyID:
		{
		    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daFamilyDvdPanels)
		    Pulse[vdvFamilyDvd,1] // rebuild events
		}
		//Case cnMBedID:
		//{
		//    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daMBedDvdPanels)
		//    Pulse[vdvMBedDvd,1] // rebuild events
		//}
	    }
	    Send_Command dvDevice,"'PAGE-VIDEO Blu-ray Player'"
	    //Send_Command dvDevice,"'@PPN-VIDEO Blu-ray Networked'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 4: // Local PS3
	{
	    Send_Command dvDevice,"'PAGE-AUDIO No Control Page'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 5: // Kitchen PC
	{
	    Send_Command dvDevice,"'PAGE-AUDIO No Control Page'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 6: // Family iPod
	{
	    Send_Command dvDevice,"'PAGE-AUDIO IPOD Main Page'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 7: // Family CD
	{
	    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daFamilyCDPanels)
	    Pulse[vdvFamilyCD,1] // rebuild events
	    Send_Command dvDevice,"'PAGE-AUDIO CD Player Page'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
	Case 8: // Family Sat Music
	{
	    Call 'ADD_PANEL_TO_SOURCE' (dvDevice, daFamilySatMusicPanels)
	    Pulse[vdvFamilyDtv,255] // rebuild events
	    Send_Command dvDevice,"'PAGE-AUDIO Sat Music'"
	    Send_Command dvDevice,"'@PPN-',strSubSystemPage"
	}
    }
}


// 1- Off
// 2- Source1 Local DTV
// 3- Source2 Local DVD
// 4- Source3 Local PS3
// 5- Source4 Kitchen PC
// 6- Source5 Family iPod
// 7- Source6 Family CD
// 8- Source7 Sat Music

Define_Call 'IPAD_DISCONNECT_SOURCE' (Dev dvPanel, Integer nTPIndex, Integer nButton)
{
    Switch (nButton)
    {
	Case 1:
	{
	    Off[dvPanel,cnOffConfirmation]
	}
	Case 2: // Local DTV
	{
	    Switch (sUI[nTPIndex].nZone)
	    {
		Case cnFamilyID:
		{
		    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daFamilyDtvPanels)
		    Pulse[vdvFamilyDtv,255] // rebuild events
		}
		//Case cnMBedID:
		//{
		//    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daMBedDtvPanels)
		//    Pulse[vdvMBedDtv,255] // rebuild events
		//}
	    }
	}
	Case 3: // Local DVD
	{
	    Switch (sUI[nTPIndex].nZone)
	    {
		Case cnFamilyID:
		{
		    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daFamilyDvdPanels)
		    Pulse[vdvFamilyDvd,1] // rebuild events
		}
		//Case cnMBedID:
		//{
		//    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daMBedDvdPanels)
		//    Pulse[vdvMBedDvd,1] // rebuild events
		//}
	    }
	}
	Case 4: // Local PS3
	Case 5: // Kitchen PC
	Case 6: // Family iPod
	{
	}
	Case 7: // Family CD
	{
	    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daFamilyCDPanels)
	    Pulse[vdvFamilyCD,1] // rebuild events
	}
	Case 8: // Family Sat Music
	{
	    Call 'REMOVE_PANEL_FROM_SOURCE' (dvPanel, daFamilySatMusicPanels)
	    Pulse[vdvFamilyDtv,255] // rebuild events
	}
    }
}

Define_Call 'IPAD_ZONE_SETUP' (Dev dvPanel, Integer nTPIndex)
{
    Stack_Var Char strSubSystemPage[30]
    Call 'DEBUG_OUTPUT' (__LINE__,"'sUI[',Itoa(nTPIndex),'].nZone:',Itoa(sUI[nTPIndex].nZone)")
    Send_Command dvPanel,"'^SHO-',Itoa(cn3dAddress),',0'" // Disable 3d Button
    Switch (sUI[nTPIndex].nZone)
    {
	Case cnFamilyID:
	Case cnMBedID:
	{
	    Send_Command dvPanel,"'^DPF-5,Show,SOURCE Select Subsystem 01'" // clear previous popup for subsystem
	    Send_Command dvPanel,"'^APF-5,Show,SOURCE Select Subsystem 02'" // add correct popup for subsystem

	    Send_Command dvPanel,"'^DPF-6,Show,SOURCE Select Subsystem 01'" // clear previous popup for subsystem
	    Send_Command dvPanel,"'^APF-6,Show,SOURCE Select Subsystem 02'" // add correct popup for subsystem

	    Send_Command dvPanel,"'^DPF-6,Show,SOURCES VIDEO Choose Source 02'" // clear previous popup for sources
	    Send_Command dvPanel,"'^APF-6,Show,SOURCES VIDEO Choose Source 01'" // add correct popup for sources
	    strSubSystemPage = 'SOURCE Select Subsystem 02'
	}
	Default: // basic audio zones
	{
	    Send_Command dvPanel,"'^DPF-5,Show,SOURCE Select Subsystem 02'" // clear previous popup for subsystem
	    Send_Command dvPanel,"'^APF-5,Show,SOURCE Select Subsystem 01'" // add correct popup for subsystem
	    strSubSystemPage = 'SOURCE Select Subsystem 01'
	}
    }
    Send_Command dvPanel,"'PAGE-START Main Page'"
    Send_Command dvPanel,"'@PPN-',strSubSystemPage"
    Send_Command dvPanel,"'@PPN-WEATHER Popup'"
}

Define_Call 'DISPLAY_ZONE_LIST' (Dev dvPanel, Integer nTPIndex)
{
    Stack_Var Integer nI
    
    Call 'DEBUG_OUTPUT' (__LINE__,"'sUI[',Itoa(nTPIndex),'].nZoneListLen:',Itoa(sUI[nTPIndex].nZoneListLen),' .nZoneListPos',Itoa(sUI[nTPIndex].nZoneListPos)")
    For (nI = 1; nI <= sUI[nTPIndex].nZoneListLen; nI++)
    {
	If (sUI[nTPIndex].nZoneListPos + nI <= cnMaxRooms)
	{
	    Send_Command dvPanel,"'TEXT',Itoa(nZoneListRoomTextChans[nI]),'-',sRoomInfo[sUI[nTPIndex].nZoneListPos + nI].strName"
	    If (sUI[nTPIndex].nZoneListPos + nI == sUI[nTPIndex].nZone)
	    {
		On[dvPanel,nZoneListSelectButtons[nI]]
	    }
	    Else
	    {
		Off[dvPanel,nZoneListSelectButtons[nI]]
	    }
	}
	Else
	{
	    Send_Command dvPanel,"'TEXT',Itoa(nZoneListRoomTextChans[nI]),'-'"
	    Off[dvPanel,nZoneListSelectButtons[nI]]
	}
    }
}

Define_Call 'DISPLAY_SCROLLING_ZONE_LIST' (Dev dvPanel, Integer nTPIndex)
{
    Stack_Var Integer nI
    Stack_Var Char strTempSourceName[25]
    
    Call 'DEBUG_OUTPUT' (__LINE__,"'sUI[',Itoa(nTPIndex),'].nZoneListLen:',Itoa(sUI[nTPIndex].nZoneListLen),' .nZoneListPos',Itoa(sUI[nTPIndex].nZoneListPos)")
    Send_Command dvPanel, "'^LDD-',Itoa(nZoneListAddress)" // Deletes any existing data list
    Send_Command dvPanel, "'^LDN-',Itoa(nZoneListPort),',',Itoa(nZoneListAddress),',5,Zone List'"  // Creates new 5-column data list  
    Send_Command dvPanel, "'^LDT-',Itoa(nZoneListAddress),',1,0,0,0,1,3'"  // Starting Column, Room Number, Room Name, Room Source, Bitmap, Port-Channel
    For (nI = 1; nI <= cnMaxRooms; nI++)
    {
	If (sRoomInfo[nI].nCurrentSource == 0)
	{
	    strTempSourceName = 'Off'
	}
	Else
	{
	    strTempSourceName = sSourceInfo[sRoomInfo[nI].nCurrentSource].strName
	}
	
	Send_Command dvPanel,"'^LDA-',Itoa(nZoneListAddress),',0,',Itoa(sRoomInfo[nI].nID),',',sRoomInfo[nI].strName,',',strTempSourceName,',background_feedback_trans.png,"',Itoa(nZoneListPort),',',Itoa(nZoneListSelectButtons[nI]),'"'"
	If (nI == sUI[nTPIndex].nZone)
	{
	    Call 'DEBUG_OUTPUT' (__LINE__,"'On[dvPanel,nZoneListSelectButtons[',Itoa(nI),']]',Itoa(nZoneListSelectButtons[nI])")
	    On[dvPanel,nZoneListSelectButtons[nI]]
	}
	Else
	{
	    Off[dvPanel,nZoneListSelectButtons[nI]]
	}
    }
    Send_Command dvPanel, "'^LVL-',Itoa(nZoneListViewAddress),',',Itoa(nZoneListPort),',',Itoa(nZoneListAddress)" //set the data list displayed.
    Send_Command dvPanel, "'^LVC-',Itoa(nZoneListViewAddress),',2'"  //Sets the column numbers to display in the view
    Send_Command dvPanel, "'^LVU-',Itoa(nZoneListViewAddress)" //Updates the view
}

(***********************************************************)
(*                STARTUP CODE GOES BELOW                  *)
(***********************************************************)
DEFINE_START

(***********************************************************)
(*                THE EVENTS GO BELOW                      *)
(***********************************************************)
DEFINE_EVENT

Data_Event[daAllUIs]
{
    Online:
    {
	Send_Command Data.Device,"'TPAGEON'"
    }
    String:
    {
	Local_Var Integer nTP, nClimateActive[cnMaxUIs]
	nTP = Get_Last(daAllUIs)
	Call 'DEBUG_OUTPUT' (__LINE__,Data.Text)
	If (Find_String(Data.Text,'PAGE-',1))
	{
	    strJunk = Remove_String(Data.Text,'PAGE-',1)
	    /*
	    If (Data.Text == 'CLIMATE Basic Page' || Data.Text == 'CLIMATE Basic Display Page')
	    {
		Send_Command vdvStat,"'PANEL_ACTIVE',Itoa(nTP),'=1'"
		nClimateActive[nTP] = 1
	    }
	    Else If (Data.Text == 'CLIMATE Zones Page')
	    {
		Send_Command vdvStat,"'PANEL_ACTIVE',Itoa(nTP),'=2'"
		nClimateActive[nTP] = 1
	    }
	    Else If (nClimateActive[nTP])
	    {
		Send_Command vdvStat,"'PANEL_ACTIVE',Itoa(nTP),'=0'"
	    }
	    */
	    If (Data.Text == 'AUDIO GLOBAL Main Page' || 'Global' || 'Global Source')
	    {
		Send_Command vdvGlobalComms,"'PANEL_ACTIVE',Itoa(nTP),'=1'"
		sUI[nTP].nGlobalActive = 1
	    }
	    Else If (sUI[nTP].nGlobalActive)
	    {
		Send_Command vdvGlobalComms,"'PANEL_ACTIVE',Itoa(nTP),'=0'"
		sUI[nTP].nGlobalActive = 0
	    }
	}
	Else If (Find_String(Data.Text,'@PPN-AUDIO GLOBAL Share Source',1))
	{
	    Send_Command vdvGlobalShareComms,"'PANEL_ACTIVE',Itoa(nTP),'=',Itoa(sUI[nTP].nZone),',',Itoa(sRoomInfo[sUI[nTP].nZone].nCurrentSource)"
		sUI[nTP].nGlobalActive = 1
	}
	Else If (Find_String(Data.Text,'@PPF-AUDIO GLOBAL Share Source',1))
	{
	    Send_Command vdvGlobalShareComms,"'PANEL_ACTIVE',Itoa(nTP),'=0,0'"
		sUI[nTP].nGlobalActive = 0
	}
	Else If (Find_String(Data.Text,'@PPN-COMMON Select Room',1))
	{
	    Call 'DISPLAY_SCROLLING_ZONE_LIST' (Data.Device, nTP)
	}
    }
}

Button_Event[daAllUIs,29] // House off
{
    Push:
    {
	Send_Command vdvInterRoomComms,"'SWITCHROOM0=0'" // turn off every room
    }
}

Channel_Event[daAllUIs,nGlobalSourceSelectButtons]
{
    On:
    {
	nGlobalSourceSelection = Get_Last(nGlobalSourceSelectButtons)
    }
}

Button_Event[daAllUIs,nGlobalSourceControlButton]
{
    Push:
    {
	Stack_Var Integer nI
	For (nI = 1; nI <= Max_Length_Array(nRoomButtons)-3; nI++) // dont go through volume buttons.
	{
	    Call 'DEBUG_OUTPUT' (__LINE__,"'Off nRoomButtons[',Itoa(nI),']:',Itoa(nRoomButtons[nI])")
	    Off[Button.Input.Device,nRoomButtons[nI]]
	}
	Call 'DEBUG_OUTPUT' (__LINE__,"'On nRoomButtons[',Itoa(nI),']:',Itoa(nRoomButtons[nGlobalSourceSelection])")
	On[Button.Input.Device,nRoomButtons[nGlobalSourceSelection]]
    }
}

//////////////////////////////
// Begin Ipad page control  //
//////////////////////////////
Data_Event[daAllIpads]
{
    Online:
    {
	Call 'IPAD_ZONE_SETUP' (Data.Device, Get_Last(daAllIpads))
    }
}

Channel_Event[daAllIPads,nRoomButtons]
{
    On:
    {
	Stack_Var Integer nButton
	
	nButton = Get_last(nRoomButtons)
	Call 'DEBUG_OUTPUT' (__LINE__,"'On Get_last(nRoomButtons)=',Itoa(nButton)")
	If (nButton <= cnMaxSources + 1 && ![Channel.Device,nGlobalDisableConnectChan]) // make sure its a valid source and that we didnt just select something from global
	{
	    Send_Command Channel.Device,"'@PPX'"
	    Call 'IPAD_PAGE_FLIPS' (Channel.Device, nButton, Get_Last(daAllIpads))
	}
    }
    Off:
    {
	Stack_Var Integer nButton
	
	nButton = Get_Last(nRoomButtons)
	Call 'DEBUG_OUTPUT' (__LINE__,"'Off Get_last(nRoomButtons)=',Itoa(nButton)")
	If (nButton <= cnMaxSources + 1 && ![Channel.Device,nGlobalDisableConnectChan]) // make sure its a valid source and that we didnt just select something from global
	{
	    Call 'IPAD_DISCONNECT_SOURCE' (Channel.Device, Get_Last(daAllIpads), nButton)
	}
    }
}
// End Ipad page controls

Button_Event[daAllUIs,cnOffConfirmation]
{
    Push:
    {
	//If (sUI[Get_Last(daAllUIs)].nZone == cnTheaterAV)
	//{
	//    Send_Command Button.Input.Device,"'@PPN-COMMON Room Off'"
	//}
	//Else
	//{
	    Do_Push (Button.Input.Device,nRoomButtons[1])
	//}
    }
}

// Begin Floating Panel
Button_Event[daAllUIs,nZoneListSelectButtons]
{
    Push:
    {
	Stack_var Integer nTPIndex
	
	nTPIndex = Get_Last(daAllUIs)
	
	Switch (sUI[nTPIndex].nZone)
	{
	    Case cnFamilyID:
	    {
		Call 'REMOVE_PANEL_FROM_ZONE' (Button.Input.Device, daFamilyPanels)
		Send_Command vdvFamilyAV,"'REBUILD_EVENTS'"
	    }
	    Case cnKitchenID:
	    {
		Call 'REMOVE_PANEL_FROM_ZONE' (Button.Input.Device, daKitchenPanels)
		Send_Command vdvKitchenA,"'REBUILD_EVENTS'"
	    }
	    Case cnPatioID:
	    {
		Call 'REMOVE_PANEL_FROM_ZONE' (Button.Input.Device, daPatioPanels)
		Send_Command vdvPatioA,"'REBUILD_EVENTS'"
	    }
	    Case cnGarageID:
	    {
		Call 'REMOVE_PANEL_FROM_ZONE' (Button.Input.Device, daGaragePanels)
		Send_Command vdvGarageA,"'REBUILD_EVENTS'"
	    }
	    Case cnMBathID:
	    {
		Call 'REMOVE_PANEL_FROM_ZONE' (Button.Input.Device, daMBathPanels)
		Send_Command vdvMBathA,"'REBUILD_EVENTS'"
	    }
	}
	Switch (sRoomInfo[sUI[nTPIndex].nZone].nCurrentSource)
	{
	    Case cnFamilyDTVID: // Local DTV
	    {
		Call 'REMOVE_PANEL_FROM_SOURCE' (Button.Input.Device, daFamilyDtvPanels)
		Pulse[vdvFamilyDtv,255] // rebuild events
	    }
	    Case cnFamilyDVDID: // Local DVD
	    {
		Call 'REMOVE_PANEL_FROM_SOURCE' (Button.Input.Device, daFamilyDvdPanels)
		Pulse[vdvFamilyDvd,1] // rebuild events
	    }
	    Case cnFamilyCDID: // Family CD
	    {
		Call 'REMOVE_PANEL_FROM_SOURCE' (Button.Input.Device, daFamilyCDPanels)
		Pulse[vdvFamilyCD,1] // rebuild events
	    }
	    Case cnSatMusicID: // Family Sat Music
	    {
		Call 'REMOVE_PANEL_FROM_SOURCE' (Button.Input.Device, daFamilySatMusicPanels)
		Pulse[vdvFamilyDtv,255] // rebuild events
	    }
	}

	sUI[nTPIndex].nZone = Get_last(nZoneListSelectButtons) + sUI[nTPIndex].nZoneListPos
	Switch (sUI[nTPIndex].nZone)
	{
	    Case cnFamilyID: 
	    {
		Call 'ADD_PANEL_TO_ZONE' (Button.Input.Device, daFamilyPanels)
		Send_Command vdvFamilyAV,"'REBUILD_EVENTS'"
	    }
	    Case cnKitchenID:
	    {
		Call 'ADD_PANEL_TO_ZONE' (Button.Input.Device, daKitchenPanels)
		Send_Command vdvKitchenA,"'REBUILD_EVENTS'"
	    }
	    Case cnPatioID:
	    {
		Call 'ADD_PANEL_TO_ZONE' (Button.Input.Device, daPatioPanels)
		Send_Command vdvPatioA,"'REBUILD_EVENTS'"
	    }
	    Case cnGarageID:
	    {
		Call 'ADD_PANEL_TO_ZONE' (Button.Input.Device, daGaragePanels)
		Send_Command vdvGarageA,"'REBUILD_EVENTS'"
	    }
	    Case cnMBathID:
	    {
		Call 'ADD_PANEL_TO_ZONE' (Button.Input.Device, daMBathPanels)
		Send_Command vdvMBathA,"'REBUILD_EVENTS'"
	    }
	}
	Switch (sRoomInfo[sUI[nTPIndex].nZone].nCurrentSource)
	{
	    Case cnFamilyDTVID: // Local DTV
	    {
		Call 'ADD_PANEL_TO_SOURCE' (Button.Input.Device, daFamilyDtvPanels)
		Pulse[vdvFamilyDtv,255] // rebuild events
	    }
	    Case cnFamilyDVDID: // Local DVD
	    {
		Call 'ADD_PANEL_TO_SOURCE' (Button.Input.Device, daFamilyDvdPanels)
		Pulse[vdvFamilyDvd,1] // rebuild events
	    }
	    Case cnFamilyCDID: // Family CD
	    {
		Call 'ADD_PANEL_TO_SOURCE' (Button.Input.Device, daFamilyCDPanels)
		Pulse[vdvFamilyCD,1] // rebuild events
	    }
	    Case cnSatMusicID: // Family Sat Music
	    {
		Call 'ADD_PANEL_TO_SOURCE' (Button.Input.Device, daFamilySatMusicPanels)
		Pulse[vdvFamilyDtv,255] // rebuild events
	    }
	}

	If (nTPIndex <= cnMaxIpads)
	{
	    Call 'IPAD_ZONE_SETUP' (Button.Input.Device, nTPIndex)
	}
	Send_Command Button.Input.Device,"'@PPF-COMMON Select Room'"
    }
}

Button_Event[daAllUIs,nZoneListScrollTopButton]
{
    Push:
    {
	Stack_var Integer nTPIndex
	
	nTPIndex = Get_Last(daAllUIs)
	sUI[nTPIndex].nZoneListPos =  0
	Call 'DISPLAY_ZONE_LIST' (Button.Input.Device, nTPIndex)
    }
}

Button_Event[daAllUIs,nZoneListScrollDownButton]
{
    Push:
    {
	Stack_var Integer nTPIndex
	
	nTPIndex = Get_Last(daAllUIs)
	If (sUI[nTPIndex].nZoneListPos + (sUI[nTPIndex].nZoneListLen*2) <=  cnMaxRooms)
	{
	    sUI[nTPIndex].nZoneListPos =  sUI[nTPIndex].nZoneListPos + sUI[nTPIndex].nZoneListLen
	}
	Else
	{
	    sUI[nTPIndex].nZoneListPos =  cnMaxRooms - sUI[nTPIndex].nZoneListLen
	}
	Call 'DISPLAY_ZONE_LIST' (Button.Input.Device, nTPIndex)
    }
}

Button_Event[daAllUIs,nZoneListScrollUpButton]
{
    Push:
    {
	Stack_var Integer nTPIndex
	
	nTPIndex = Get_Last(daAllUIs)
	If (sUI[nTPIndex].nZoneListPos >= sUI[nTPIndex].nZoneListLen)
	{
	    sUI[nTPIndex].nZoneListPos =  sUI[nTPIndex].nZoneListPos - sUI[nTPIndex].nZoneListLen
	}
	Else
	{
	    sUI[nTPIndex].nZoneListPos =  0
	}
	Call 'DISPLAY_ZONE_LIST' (Button.Input.Device, nTPIndex)
    }
}
// End Floaing panel

Channel_Event[daAllDMS,nRoomButtons]
{
    On:
    {
	Stack_Var Integer nButton, nI
	nButton = Get_Last(nRoomButtons)
	If (nButton == 1) // Off
	{
	    Off[Channel.Device,28] // LED Feedback
	}
	Else If (nButton <= 11)
	{
	    On[Channel.Device,28]
	    Switch (Get_last(nRoomButtons))
	    {
		Case 6: // Family iPod
		{
		    Send_Command Channel.Device,"'PAGE-IPOD Main'"
		}
		Case 7: // Family CD
		{
		    Call 'ADD_PANEL_TO_SOURCE' (Channel.Device, daFamilyCDPanels)
		    Pulse[vdvFamilyCD,1] // rebuild events
		    Send_Command Channel.Device,"'PAGE-CD Page'"
		}
		Case 8: // Family Sat Music
		{
		    Call 'ADD_PANEL_TO_SOURCE' (Channel.Device, daFamilySatMusicPanels)
		    Pulse[vdvFamilyDtv,255] // rebuild events
		    Send_Command Channel.Device,"'PAGE-Sat Music'"
		}
	    }
	}
    }
    Off:
    {
	Stack_Var Integer nButton, nI
	nButton = Get_Last(nRoomButtons)
	If (nButton <= 11)
	{
	    Switch (Get_last(nRoomButtons))
	    {
		Case 6: // Family iPod
		{
		}
		Case 7: // Family CD
		{
		    Call 'REMOVE_PANEL_FROM_SOURCE' (Channel.Device, daFamilyCDPanels)
		    Pulse[vdvFamilyCD,1] // rebuild events
		}
		Case 8: // Family Sat Music
		{
		    Call 'REMOVE_PANEL_FROM_SOURCE' (Channel.Device, daFamilySatMusicPanels)
		    Pulse[vdvFamilyDtv,255] // rebuild events
		}
	    }
	}
    }
}

Button_Event[vdvKitchenKP,28] // re direct zone off button
{
    Push:
    {
	Send_Command vdvInterRoomComms,"'SWITCHROOM',Itoa(cnKitchenID),'=0'"
    }
}

Button_Event[vdvGarageKP,28] // re direct zone off button
{
    Push:
    {
	Send_Command vdvInterRoomComms,"'SWITCHROOM',Itoa(cnGarageID),'=0'"
    }
}

Button_Event[vdvMBathKP,28] // re direct zone off button
{
    Push:
    {
	Send_Command vdvInterRoomComms,"'SWITCHROOM',Itoa(cnMBathID),'=0'"
    }
}

(***********************************************************)
(*            THE ACTUAL PROGRAM GOES BELOW                *)
(***********************************************************)
DEFINE_PROGRAM

(***********************************************************)
(*                     END OF PROGRAM                      *)
(*        DO NOT PUT ANY CODE BELOW THIS COMMENT           *)
(***********************************************************)

